
original_function = @(x) 1./(1 + 25*x.^2);
a = {
	@(x)	(-1 <= x & x <= -0.6) .* (1.87882 + 6.21788*x.^1 + 6.98867*x.^2 + 2.61114*x.^3) + ...
(-0.6 <= x & x <= -0.2) .* (0.549416 - 0.429111*x.^1 - 4.08965*x.^2 - 3.54348*x.^3) + ...
(-0.2 <= x & x <= 0.2) .* (0.577959 - 0.000973217*x.^1 - 1.94896*x.^2 + 0.0243304*x.^3) + ...
(0.2 <= x & x <= 0.6) .* (0.550584 + 0.409647*x.^1 - 4.00206*x.^2 + 3.44616*x.^3) + ...
(0.6 <= x & x <= 1) .* (1.78539 - 5.76436*x.^1 + 6.28796*x.^2 - 2.27052*x.^3)
};

x = linspace(-1, 1, 1000);
y_original = original_function(x);
y_piecewise = cellfun(@(func) func(x), a, 'UniformOutput', false);
y_combined_piecewise = sum(cat(3, y_piecewise{:}), 3);

% 绘制图形
figure;
plot(x, y_original, 'LineWidth', 2, 'DisplayName', '原函数');
hold on;
plot(x, y_combined_piecewise, '-', 'LineWidth', 1, 'DisplayName', '样条函数');
xlabel('x');
ylabel('f(x)');
title('样条P函数与精准函数对比');
legend('show');
grid on;
hold off;
